package com.example.handler;

import com.example.pojo.Product;
import com.example.services.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
public class ProductController {

    @Autowired
    ProductService productService;

    @RequestMapping("/import/doc")
    public String hello() {
        List<Product> list = productService.getAllProduct();
        boolean con = productService.importProductToESDoc(list);
        return con + "";
    }

    @GetMapping("/")
    public List<Map<String, Object>> getProduct(@RequestParam("pageOn") Integer pageOn,
                                                @RequestParam("count") Integer count,
                                                @RequestParam("keyword") String keyword) {

        List<Map<String, Object>> maps = productService.SearchProduct(pageOn, count, keyword);
        return maps;
    }
}
